import { DD_SYSTEM } from '@/constants/api-pre';
import { request } from '@/service/request';

export type SmsLog = Api.Common.CommonRecord<{
  channelId: number | null;
  channelCode: string;
  templateId: string;
  templateCode: string;
  templateType: number | string;
  templateContent: string;
  templateParams: Map<string, object> | null;
  apiTemplateId: string;
  mobile: string;
  userId: number | null;
  userType: number | null;
  sendStatus: number | string;
  sendTime: Date | null;
  apiSendCode: string;
  apiSendMsg: string;
  apiRequestId: string;
  apiSerialNo: string;
  receiveStatus: number | string;
  receiveTime: Date | null;
  apiReceiveCode: string;
  apiReceiveMsg: string;
}>;

export type SmsLogList = Api.Common.PaginatingQueryRecord<SmsLog>;

export type SmsLogSearchParams = CommonType.RecordNullable<
  Pick<SmsLog, 'mobile' | 'channelId' | 'templateId' | 'sendStatus' | 'sendTime' | 'receiveStatus' | 'receiveTime'> &
    Api.Common.CommonSearchParams
>;

export function fetchSmsLogList(params?: SmsLogSearchParams) {
  return request<SmsLogList>({
    url: `${DD_SYSTEM}/sms-log/page`,
    method: 'get',
    params
  });
}
